<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('joomla.application.component.view');
 
/**
 * KMS_Video View
 */
class KMS_VideoViewKMS_Video_Segment extends JView
{
        /**
         * display method of KMS_Video view
         * @return void
         */
        public function display($tpl = null) 
        {
                // get the Data
                $form = $this->get('Form');
                $item = $this->get('Item');
                $jinput = JFactory::getApplication()->input;
 
                // Check for errors.
                if (count($errors = $this->get('Errors'))) 
                {
                        JError::raiseError(500, implode('<br />', $errors));
                        return false;
                }
                // Assign the Data
                $this->form = $form;
                $this->item = $item;
				$this->labels = $this->getLabels();
				
				if($this->item->video_id == 0 || empty($this->item->video_id))
				{
					$this->item->video_id = $jinput->getInt('video_id');
				}
				
                // Set the toolbar
                $this->addToolBar();
                
 
                // Display the template
                parent::display($tpl);
        }
 
        /**
         * Setting the toolbar
         */
        protected function addToolBar() 
        {
                $input = JFactory::getApplication()->input;
                $input->set('hidemainmenu', true);
                
                JToolBarHelper::title(JText::_('COM_KMS_VIDEO_KMS_SEGMENT_DETAILS'));
                JToolBarHelper::apply('kms_video_segment.save');
                JToolBarHelper::save('kms_video_segment.save');
                JToolBarHelper::cancel('kms_video_segment.cancel', 'JTOOLBAR_CLOSE');
        }
        
        public function getVideoName()
        {
				$db = JFactory::getDBO();
                $query = $db->getQuery(true);
                $query->select('video_name');
                $query->from('#__kms_videos');
                $query->where('video_id = ' . $this->item->video_id);
                $db->setQuery((string)$query);
                $r = $db->loadObjectList();
                
                return $r[0]->video_name;
		}
		
		public function getLabels()
		{
				$db = JFactory::getDBO();
                $query = $db->getQuery(true);
                $query = 'select b.label_id, a.label_value from #__kms_labels AS a inner join #__kms_labels_segments AS b where a.label_id = b.label_id and b.segment_id = ' . $this->item->segment_id;
                $db->setQuery((string)$query);
                $r = $db->loadObjectList();
                
                return $r;
		}
}
